import {Column, Entity, OneToOne} from 'typeorm';
import {CommonEntity} from '~/common/entity/common.entity';
import {UserEntity} from '../user.entity';

@Entity({name: 'sys_user_wechat'})
export class UserWechatEntity extends CommonEntity {
  @Column({type: 'varchar', length: 150, unique: true, comment: '微信openid'})
  openid: string;

  @Column({type: 'varchar', length: 150, nullable: true, comment: '微信unionid'})
  unionid: string;

  @Column({type: 'varchar', length: 50, nullable: true, comment: '微信昵称'})
  nickname: string;

  @Column({type: 'varchar', length: 255, nullable: true, comment: '微信头像'})
  avatar: string;

  @Column({
    type: 'tinyint',
    nullable: true,
    default: 1,
  })
  status: number;

  @Column({type: 'varchar', length: 50, nullable: true, comment: '联系电话'})
  phone: string;

  @Column({
    type: 'int',
    nullable: true,
    comment: '用户年龄',
		default: 0,
  })
  age: number;

  @Column({
    type: 'int',
    default: 0,
    comment: '健康积分',
		name: 'health_points',
  })
  healthPoints: number;

	@Column({
    type: 'decimal',
    precision: 5,
    scale: 2,
    comment: '体质指数（Body Mass Index）',
		default: 0,
  })
  bmi: number;

  @Column({
    type: 'int',
    comment: '收缩压（mmHg）',
		name: 'blood_pressure_sbp',
		default: 0,
  })
  bloodPressureSbp: number;

  @Column({
    type: 'int',
    comment: '舒张压（mmHg）',
		name: 'blood_pressure_dbp',
		default: 0,
  })
  bloodPressureDbp: number;

  @Column({
    type: 'decimal',
    precision: 5,
    scale: 2,
    comment: '空腹血糖（mmol/L）',
		name: 'fasting_blood_glucose',
		default: 0,
  })
  fastingBloodGlucose: number;

  @Column({
    type: 'decimal',
    precision: 5,
    scale: 2,
    comment: '低密度脂蛋白（mmol/L）',
		name: 'ldl_cholesterol',
		default: 0,
  })
  ldlCholesterol: number;

  @Column({
    type: 'decimal',
    precision: 6,
    scale: 2,
    comment: '血尿酸（μmol/L）',
		name: 'uric_acid',
		default: 0,
  })
  uricAcid: number;

  @OneToOne(() => UserEntity, (user) => user.wechat, {
    onDelete: 'CASCADE',
    onUpdate: 'CASCADE',
    cascade: ['insert', 'update'],
  })
  user: UserEntity;
}
